﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using EnvironmentalMonitor.Support.Business.Environmental;
using EnvironmentalMonitor.Support.Business;
using EnvironmentalMonitor.Support.Module;
using EnvironmentalMonitor.Support.Resource;

namespace EnvironmentalMonitor.WebApplication.Environmental.Machine.Setup
{
    /// <summary>
    /// 普通设置保存Json数据页面类
    /// </summary>
    public partial class NormalSaveJson : EnvironmentalMonitor.WebApplication.Abstract.AbstractSaveJson
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            const string GUID = "guid";

            const string IP = "ip";
            const string FLOOR_PLAN = "floorplan";

            EnvironmentalMonitor.Support.Module.Manage.User sessionUser = this.Session[Constant.SESSION_KEY_USER] as EnvironmentalMonitor.Support.Module.Manage.User;
            DateTime now = DateTime.Now;

            EnvironmentalMonitor.Support.Module.Environmental.Machine module = new Support.Module.Environmental.Machine();
            module.Guid = this.ParameterString(GUID);
            module.UpdateUserId = sessionUser.Guid;
            module.UpdateTime = now;

            module.Ip = this.ParameterString(IP);
            module.FloorPlan = string.Format("Upload/Machine/FloorPlan/{0}.jpg", module.Guid);
            string url = string.Format("{0}{1}", EnvironmentalMonitor.Support.Resource.Variable.VirtualRootPath, module.FloorPlan);
            this.ParameterFile(FLOOR_PLAN, url);

            this.SaveJsonData = new Abstract.SaveJsonData();
            MachineBusiness business = new MachineBusiness();
            this.SaveJsonData.success = business.UpdateNormal(module);
            if (!this.SaveJsonData.success)
            {
                this.SaveJsonData.msg = "数据操作失败！";
            }

            string json = this.Json();

            this.Response.Write(json);
            this.Response.Flush();
            this.Response.End();
        }
    }
}